package com.cssw.fyzb.busi.service.team;

import com.cssw.fyzb.busi.service.user.UserServiceImpl;
import com.cssw.fyzb.busi.util.TimeUtil;
import com.cssw.fyzb.core.dao.team.UserTreeDao;
import com.cssw.fyzb.core.model.dodb.User;
import com.ydn.dbframe.plugin.activerecord.Page;
import com.ydn.dbframe.plugin.activerecord.Record;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TeamServiceImpl implements TeamService{

    private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);

    @Autowired
    private UserTreeDao userTreeDao;

    @Value("${task.teamDate:2021-02-05 00:00:00}")
    private String taskTeamDate;


    @Override
    public Page<User> pageTeamList(Long userId, Integer pageNumber, Integer pageSize,Integer type) {
        Map param = new HashMap<>();
        param.put("userId", userId);
        if(type==0){
            return userTreeDao.getAllSuberBySupArr(param, pageNumber, pageSize);
        }
        if (type==1){
            param.put("faceAuth", 1);
        }else if(type==2){
            param.put("faceAuth", 0);
        }
        return userTreeDao.getSuberBySupArr(param, pageNumber, pageSize);
    }

    @Override
    public Integer getTeamNum(Long userId) {
        return userTreeDao.getTeamNum(userId);
    }

    @Override
    public List<Record> listTeamForDate(Long userId, Date date) {
        return userTreeDao.listTeamForDate(userId, date);
    }

    @Override
    public Integer countTaskTeamNum(Long userId) {
        return userTreeDao.countTaskTeamNum(userId, TimeUtil.parse(taskTeamDate, TimeUtil.FORMAT_YYYYMMDDHHMMSS));
    }
}
